package com.itheima.app.controller.umsController;

import com.itheima.app.manager.umsManager.UmsResourceManager;
import com.itheima.commons.R;
import com.itheima.domain.db.ums.UmsResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UmsResourceController {

    //TODO:江云天 -资源列表

    @Autowired
    private UmsResourceManager umsResourceManager;

    /**
     * 添加后台资源
     * @param umsResource
     * @return
     */
    @PostMapping("/resource/create")
    public R create(@RequestBody UmsResource umsResource) {
        return umsResourceManager.create(umsResource);
    }

    /**
     * 根据ID删除后台资源
     * @param id
     * @return
     */
    @PostMapping("/resource/delete/{id}")
    public R delete(@PathVariable Long id) {
        return umsResourceManager.delete(id);
    }


    /**
     * 分页模糊查询后台资源
     * @return
     */
    @GetMapping("/resource/list")
    public R getByCondiction(Long categoryId, String nameKeyword, Integer pageNum,
                             Integer pageSize, String urlKeyword) {
        return umsResourceManager.getByCondiction(categoryId, nameKeyword, pageNum, pageSize, urlKeyword);
    }

    /**
     * 查询所有后台资源
     * @return
     */
    @GetMapping("/resource/listAll")
    public R getAll() {
        return umsResourceManager.getAll();
    }

    /**
     * 修改后台资源
     * @param id
     * @param resource
     * @return
     */
    @PostMapping("/resource/update/{id}")
    public R update(@PathVariable Long id, @RequestBody UmsResource resource) {
        return umsResourceManager.update(id, resource);
    }

    /**
     * 根据ID获取资源详情
     * @param id
     * @return
     */
    @GetMapping("/resource/{id}")
    public R getById(@PathVariable Long id) {
        return umsResourceManager.getById(id);
    }
}
